package com.miyake.loveviewweb.client.viewer.table;

import java.util.List;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Widget;
import com.miyake.loveviewweb.client.viewer.table.ContentGetter.DataModelHandler;
import com.miyake.loveviewweb.shared.model.DataColumnModel;
import com.miyake.loveviewweb.shared.model.DataModel;

public class HeaderGrid extends Grid implements ITable {

    private DataModel dataModel;

    public HeaderGrid(DataModel dataModel) {
        this.dataModel = dataModel;
        this.setBorderWidth(1);
        
        new ContentGetter(dataModel, new DataModelHandler() {
            public void onUpdate(DataModel dataModel) {
                resize(1, dataModel.getXyDataBody().getDataColumn().size());
                
                int col = 0;
                for (DataColumnModel colModel : dataModel.getXyDataBody().getDataColumn()) {
                    setWidget(0, col++, new Anchor(colModel.getHeader()));
                }
            }
        });
    }

    public Widget getUiWidget() {
        return this;
    }

    public List<DataColumnModel> getDataColumnList() {
        return dataModel.getXyDataBody().getDataColumn();
    }
}
